<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" >
<head>
    <title>微信支付</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body onload="javascript:pay();">

<script th:inline="javascript">
    function pay(){
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }
    }
    function onBridgeReady(){
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
                "appId" : [[${appid}]],         //公众号名称，由商户传入
                "timeStamp": [[${timestamp}]],   //时间戳，自1970年以来的秒数
                "nonceStr" : [[${noncestr}]],    //随机串
                "package" : [[${package}]],
                "signType" : "MD5",             //微信签名方式:
                "paySign" : [[${sign}]]          //微信签名
            },function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok"){
                  //支付成功 跳转
                  location.href="/wechat/from/"+[[${projectid}]]+"?openId="+[[${openid}]];
                }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
                    window.history.back();
                }else{
                    alert("支付失败!");
                    window.history.back();
                }
            });
    }
</script>
</body>

</html>